package org.jcnc.staffingsystem.stage;

import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import org.jcnc.staffingsystem.db.EmployeeManager;
import org.jcnc.staffingsystem.module.TextBox;

import static org.jcnc.staffingsystem.stage.loginScene.getAccount;

public class EmployeeInformationBox extends VBox {

    String account = getAccount();
    TextBox nameBox, sexBox, phoneNumberBox, addressBox, jobNumberBox, affiliationBox, postsBox;
    EmployeeManager employeeManager;

    public EmployeeInformationBox() {
        employeeManager = new EmployeeManager();


        HBox mainBox2 = new HBox(200);
        VBox mainBox3 = new VBox(40);
        VBox mainBox4 = new VBox(40);

        nameBox = new TextBox("姓名");
        nameBox.setText(employeeManager.findEmployeeNameByAccount(account));
        sexBox = new TextBox("性别");
        sexBox.setText(employeeManager.findEmployeeGenderByAccount(account));
        phoneNumberBox = new TextBox("电话");
        phoneNumberBox.setText(employeeManager.findEmployeePhoneByAccount(account));
        addressBox = new TextBox("住址");
        addressBox.setText(employeeManager.findEmployeeAddressByAccount(account));

        jobNumberBox = new TextBox("工号");
        jobNumberBox.setText(employeeManager.findEmployeeEmp_idByAccount(account));
        affiliationBox = new TextBox("部门");
        affiliationBox.setText(employeeManager.findEmployeeDepartmentByAccount(account));
        postsBox = new TextBox("职位");
        postsBox.setText(employeeManager.findEmployeePositionByAccount(account));

        mainBox3.getChildren().addAll(nameBox, sexBox, phoneNumberBox, addressBox);
        mainBox3.setPrefWidth(Region.USE_COMPUTED_SIZE);  // 设置宽度为自适应大小
        mainBox3.setPrefHeight(Region.USE_COMPUTED_SIZE); // 设置高度为自适应大小
        mainBox3.setMaxWidth(Double.MAX_VALUE);           // 允许水平方向上扩展
        mainBox3.setMaxHeight(Double.MAX_VALUE);          // 允许垂直方向上扩展
        mainBox3.setPrefSize(1000, 1000);
        mainBox4.getChildren().addAll(jobNumberBox, affiliationBox, postsBox);
        mainBox4.setPrefWidth(Region.USE_COMPUTED_SIZE);  // 设置宽度为自适应大小
        mainBox4.setPrefHeight(Region.USE_COMPUTED_SIZE); // 设置高度为自适应大小
        mainBox4.setMaxWidth(Double.MAX_VALUE);           // 允许水平方向上扩展
        mainBox4.setMaxHeight(Double.MAX_VALUE);          // 允许垂直方向上扩展
        mainBox4.setPrefSize(1000, 1000);

        mainBox2.setAlignment(Pos.CENTER);
        mainBox2.getChildren().addAll(mainBox3, mainBox4);
        mainBox2.setSpacing(50);


        Button buttonHBox = new Button("修改");
        buttonHBox.setOnAction(actionEvent -> {
            employeeManager.updateEmployeeByAccount(nameBox.getText(), jobNumberBox.getText(), sexBox.getText(),affiliationBox.getText(),
                    phoneNumberBox.getText(),postsBox.getText(),addressBox.getText(),getAccount());
        });
        buttonHBox.setAlignment(Pos.CENTER);


        this.getChildren().addAll(mainBox2, buttonHBox);
        this.setSpacing(20);
        this.setAlignment(Pos.CENTER);
        this.setPrefWidth(Region.USE_COMPUTED_SIZE);  // 设置宽度为自适应大小
        this.setPrefHeight(Region.USE_COMPUTED_SIZE); // 设置高度为自适应大小
        this.setMaxWidth(Double.MAX_VALUE);           // 允许水平方向上扩展
        this.setMaxHeight(Double.MAX_VALUE);          // 允许垂直方向上扩展
        this.setPrefSize(30000, 30000);
        this.setPadding(new Insets(80));

    }
}
